﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
public class Pools:Singleton<Pools>
{
    Dictionary<string, Pool> pools = new Dictionary<string, Pool>();
    public GameObject Spawn(string name)
    {
        if (!pools.ContainsKey(name))
            RegistPool(name);
        return pools[name].Spawn();
    }
    public void Unspawn(GameObject go)
    {
        Pool pool = null;
        foreach(var p in pools.Values)
        {
            if(p.Contain(go))
            {
                pool = p;
                break;
            }
        }
        pool.Unspawn(go);
    }
    public void UnspawnAll()
    {
        foreach(var p in pools.Values)
        {
            p.UnspawnAll();
        }
    }
    void RegistPool(string name)
    {
        string path = "Model/" + name;
        GameObject prefab = Resources.Load<GameObject>(path);
        Pool p = new Pool(transform,prefab);
        pools.Add(p.Name, p);
    }
}
